import { UserWithdrawalCash, UserTransaction, TradeOrderAndMerchantInfo, UserRecharge} from 'src/app/model';
import { WenyaoReadForm } from 'src/app/shared/components';
import { BillingDetail } from '../service/billing.service';

export function loadTradeOrderAndMerchantInfo(data: BillingDetail): WenyaoReadForm[] {
    const tradeOrderAndMerchantInfo = data as TradeOrderAndMerchantInfo;
    if (tradeOrderAndMerchantInfo) {
        return doLoadTradeOrderAndMerchantInfo(tradeOrderAndMerchantInfo);
    } else {
        return [];
    }
}

export function loadUserTransaction(data: BillingDetail): WenyaoReadForm[] {
    const userTransaction = data as UserTransaction;
    if (userTransaction) {
        return doLoadUserTransaction(userTransaction);
    } else {
        return [];
    }
}

export function loadUserWithdrawalCash(data: BillingDetail): WenyaoReadForm[] {
    const userWithdrawalCash = data as UserWithdrawalCash;
    if (userWithdrawalCash) {
        return doLoadUserWithdrawalCash(userWithdrawalCash);
    } else {
        return [];
    }
}
export function LoadUserRecharge(data: BillingDetail): WenyaoReadForm[] {
    const userRecharge = data as UserRecharge;
    if (userRecharge) {
        return doLoadUserRecharge(userRecharge);
    } else {
        return [];
    }
}


function doLoadTradeOrderAndMerchantInfo(data: TradeOrderAndMerchantInfo): WenyaoReadForm[] {
    return [
        {
            label: {
                name: '状态',
            },
            value: {
                name:  data.tradeOrder.status,
            },
        },
        // {
        //     label: {
        //         name: '状态',
        //     },
        //     value: {
        //         name: data.tradeOrder.orderAmount + ''
        //     }
        // },
        {
            label: {
                name: '商品说明',
            },
            value: {
                name: data.tradeOrder.productName
            }
        },
        {
            label: {
                name: '创建时间',
            },
            value: {
                name: data.tradeOrder.createTime,
            }
        },
        {
            label: {
                name: '订单号'
            },
            value: {
                name: data.tradeOrder.outTradeNo
            }
        },
        {
            label: {
                name: '商家订单号'
            },
            value: {
                name: data.tradeOrder.id
            }
        }
    ]
}

function doLoadUserTransaction(data: UserTransaction): WenyaoReadForm[] {
    return [
        {
            label: {
                name: '状态'
            },
            value: {
                name: data.status
            }
        },
        // {
        //     label: {
        //         name: '金额',
        //     },
        //     value: {
        //         name: data.amount + ''
        //     }
        // },
        {
            label: {
                name: '手续费',
            },
            value: {
                name: data.withdrawalFee + ''
            }
        },
        {
            label: {
                name: '实付',
            },
            value: {
                name: data.realTxFee + '',
            }
        },
        {
            label: {
                name: '对方',
            },
            value: {
                name: data.fromUserLoginId
            }
        },
        {
            label: {
                name: '创建时间',
            },
            value: {
                name: data.regDtm,
            }
        },
        {
            label: {
                name: '订单号',
            },
            value: {
                name: data.id
            },
            newRow: true,
        },
        // {
        //   label: {
        //     name: '备注',
        //   },
        //   value: {
        //     name: data.r
        //   }
        // },
        {
            label: {
                name: '转账地址',
            },
            value: {
                name: data.toAddress,
            },
            newRow: true,
        }
    ]
}

function doLoadUserWithdrawalCash(data: UserWithdrawalCash): WenyaoReadForm[] {
    return [
        // {
        //     label: {
        //         name: '金额'
        //     },
        //     value: {
        //         name: data.amount + '',
        //     }
        // },
        {
            label: {
                name: '手续费'
            },
            value: {
                name: data.withdrawalFee + '',
            }
        },
        {
            label: {
                name: '收款银行',
            },
            value: {
                name: data.bankName
            }
        },
        {
            label: {
                name: '支行',
            },
            value: {
                name: data.bankSubBranch
            }
        },
        {
            label: {
                name: '收款账号',
            },
            value: {
                name: data.bankAccountNum
            }
        },
        {
            label: {
                name: '户名',
            },
            value: {
                name: data.bankAccountName
            }
        },
        {
            label: {
                name: '订单号',
            },
            value: {
                name: data.id
            }
        },
        {
            label: {
                name: '创建时间',
            },
            value: {
                name: data.startDate || ''
            }
        },
        {
            label: {
                name: '完成时间',
            },
            value: {
                name: data.endDate || ''
            }
        },
        {
            label: {
                name: '备注',
            },
            value: {
                name: data.cancelReason || data.rejectReasn || ''
            }
        },
    ];
}


function doLoadUserRecharge(data: UserRecharge): WenyaoReadForm[] {
    return [
        {
            label: {
                name: '状态',
            },
            value: {
                name:  data.status,
            },
        },
        {
            label: {
                name: '商品说明',
            },
            value: {
                name: data.verifyCode
            }
        },
        {
            label: {
                name: '创建时间',
            },
            value: {
                name: data.createTime,
            }
        },
        {
            label: {
                name: '订单号'
            },
            value: {
                name: data.id
            }
        },
        {
            label: {
                name: '登录ID'
            },
            value: {
                name: data.loginId
            }
        },
        {
            label: {
                name: '银行名称'
            },
            value: {
                name: data.bankName
            }
        },
        {
            label: {
                name: '支行'
            },
            value: {
                name: data.bankSubBranch
            }
        },
        {
            label: {
                name: '银行卡号'
            },
            value: {
                name: data.bankAccountNum
            }
        },
        {
            label: {
                name: '账户名称'
            },
            value: {
                name: data.bankAccountName
            }
        },
        {
            label: {
                name: '交易流水号'
            },
            value: {
                name: data.bankTrxNo || '-'
            }
        },
        {
            label: {
                name: '备注'
            },
            value: {
                name: data.remark || '-'
            }
        }
    ]
}